package com.jxs.android.weiget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jxs.android.ges.R;

public class WorkLogEditSubTitle extends LinearLayout {

	private TextView index;
	private ImageView option;

	private void init(Context context) {
		LayoutInflater.from(context).inflate(R.layout.bu_work_log_detail_sub_title, this);
		index = (TextView) findViewById(R.id.index);
		option = (ImageView) findViewById(R.id.option);
	}

	public WorkLogEditSubTitle(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkLogEditItem);
		String indexstr = a.getString(R.styleable.WorkLogEditItem_index);
		boolean isEnable = a.getBoolean(R.styleable.WorkLogEditItem_enable, true);
		showAdd(isEnable);
		index.setText(indexstr);
		a.recycle();
	}

	public void setAddOptionListen(final AddOptionListen addOptionListen) {
		option.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				addOptionListen.logic(v);
			}
		});
	}

	public void setIndex(String index) {
		this.index.setText(index);
	}

	public void showAdd(boolean isEnable) {
		if (isEnable) {
			option.setVisibility(VISIBLE);
		} else
			option.setVisibility(GONE);
	}

	static public interface AddOptionListen {
		public void logic(View v);
	}

}
